package com.zw.pm.module.config.category;

import com.zw.pm.gen.entity.Category;
import com.zw.pm.gen.mapper.CategoryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.zw.pm.constant.Constant.STATUS_NORMAL;

/**
 * @Description: 会议类型 服务
 *
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@Slf4j
public class CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private CategoryDao categoryDao;

    /**
     * 按条件查询
     * @param category category
     * @return list
     */
    public List<Category> findCategoryAll(Category category) {
        return categoryDao.findCategoryAll(category);
    }

    /**
     * 修改
     *
     * @param category category
     * @return 影响行数
     */
    public int updateCategory(Category category) {
        return categoryMapper.updateByPrimaryKeySelective(category);
    }

    /**
     * 按类型名称查询
     *
     * @param name name
     * @return Category
     */
    public Category findByCategoryName(String name) {
        return categoryDao.findByCategoryName(name);
    }

    /**
     * 保存类型信息
     *
     * @param category category
     * @return 影响行数
     */
    public int saveCategory(Category category) {
        category.setStatus(STATUS_NORMAL);
        return categoryMapper.insert(category);
    }

    /**
     * 根据ID查询
     * @param id id
     * @return Category
     */
    public Category getCategory(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    /**
     * 删除
     *
     * @param category category
     * @return 影响行数
     */
    public int delCategory(Category category) {
        return categoryMapper.updateByPrimaryKeySelective(category);
    }
}
